﻿<div class="ui-box-simple">
    <div class="ui-box-simple-header">
        <h3>
            注册小米帐户</h3>
        <p>
            小米帐户能使用小米手机、米聊、MIUI和小米的其他服务。如果您已拥有小米帐户，则可<a class="cor_yellow" href="/">在此登录</a></p>
    </div>
    <div class="ui-box-simple-container">
        <div class="tabbable">
            <ul class="nav nav-tabs pl-300 f-18">
                <li class="active"><a href="#1" data-toggle="tab">用电子邮箱注册</a></li>
                <li><a href="#2" data-toggle="tab">用手机号码注册</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane active" id="1">
                    <div class="row-fluid">
                        <div class="span7 offset1">
                            <div class="passport-register passport-register-by-email">
                                <form id="form-register-by-email" class="form-horizontal" autocomplete="off" method="post" action="/register?@(Request.QueryString)">
                                <div class="control-group">
                                    <label class="control-label" for="email">
                                        电子邮箱
                                    </label>
                                    <div class="controls">
                                        <input type="text" id="email" name="email" class="input-large" autocomplete="off"
                                            maxlength="30" placeholder="电子邮箱" data-rel="popover" data-trigger="focus" data-placement="left"
                                            data-original-title="温馨提醒" data-content="使用常用邮箱作为用户名，通过验证后可用于登录和找回密码。" />
                                        <p id="input-help-email" class="input-help">
                                            使用常用邮箱作为用户名！</p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="password">
                                        登录密码</label>
                                    <div class="controls">
                                        <input type="password" id="password" name="password" class="input-large" autocomplete="off"
                                            maxlength="12" onpaste="return false" onmousedown="this.oncontextmenu = function() { return false;} "
                                            onkeydown="if(event.ctrlKey) return false;" placeholder="请输入您的登录密码" data-rel="popover"
                                            data-trigger="focus" data-placement="left" data-original-title="温馨提醒" data-content="为了您的账户安全，请输入6-12位的密码。密码至少两个字母、两个数字、一个特殊字符！（字母区分大小写）" />
                                        <p id="input-help-password" class="input-help">
                                            6-12位，至少两个字母、两个数字、一个特殊字符！</p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="repassword">
                                        确认密码</label>
                                    <div class="controls">
                                        <input type="password" id="repassword" name="repassword" class="input-large" autocomplete="off"
                                            maxlength="12" onpaste="return false;" onpaste="return false;" onmousedown="this.oncontextmenu = function() { return false;}"
                                            onkeydown="if(event.ctrlKey) return false;" placeholder="请再次输入您的登录密码" data-rel="popover"
                                            data-trigger="focus" data-placement="left" data-original-title="温馨提醒" data-content="为了您的账户安全，请输入6-12位的密码。密码至少两个字母、两个数字、一个特殊字符！（字母区分大小写）" />
                                        <p id="input-help-repassword" class="input-help">
                                            6-12位，至少两个字母、两个数字、一个特殊字符！</p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="captcha">
                                        注册验证码</label>
                                    <div class="controls">
                                        <input type="text" id="captcha" name="captcha" class="input-mini" maxlength="4" autocomplete="off"
                                            placeholder="验证码" autocomplete="off" data-rel="popover" data-trigger="focus"
                                            data-placement="left" data-title="温馨提醒" data-content="请输入图片中的4位字符。（不区分大小写）" />
                                        <img id="register-captcha-img" class="captcha-img" src="/register/captcha" onclick="this.src='/register/captcha?'+Math.random();"
                                            alt="点击刷新" />
                                        <span class="captcha-img-refresh" onclick="document.getElementById('register-captcha-img').src='/register/captcha?'+Math.random();">
                                            看不清<br />
                                            换一张</span>
                                        <p id="input-help-captcha" class="input-help">
                                            请输入图片中的4位字符。（不区分大小写）</p>
                                    </div>
                                </div>
                                <div class="form-actions border-none background-none">
                                    <span class="ui-button ui-button-ok clearfix"><span class="ui-button-left">&nbsp;</span>
                                        <button type="submit" class="ui-button-text">
                                            同意协议并注册</button><span class="ui-button-right">&nbsp;</span></span> <span><a href="">
                                                xx用户协议</a> </span>
                                </div>
                                </form>
                            </div>
                        </div>
                        <div class="span3">
                            <div class="passport-register-quick">
                                <div class="passport-register-quick-header">
                                </div>
                                <div class="passport-register-quick-container">
                                    中国大陆手机用户，<br />
                                    编辑短信”<em>SK</em>“ 发送到：
                                    <br />
                                    <span class="mobile">1069099988</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="tab-pane" id="2">
                    <div class="row-fluid">
                        <div class="span7 offset1">
                            <div class="passport-register passport-register-by-mobile">
                                <form id="form-register-by-mobile" class="form-horizontal" autocomplete="off" method="post" action="/register/bymobile/?@(Request.QueryString)">
                                <div class="control-group">
                                    <label class="control-label" for="mobile">
                                        手机号码
                                    </label>
                                    <div class="controls">
                                        <input type="text" id="mobile" name="mobile" class="input-medium" autocomplete="off"
                                            maxlength="11" placeholder="手机号码" onblur="if (!this.value.isMobile()){$('#input-help-mobile').html('<span class=\'error\'>请输入正确的手机号码！<span>');}else{$('#input-help-mobile').html('使用常用手机号码作为用户名！');}" />
                                        <p id="help-mobile" class="help-inline">
                                            <a id="control-getsmscode" href="javascript:void(0);" onclick="getSmsCode();">获取短信验证码</a>
                                            <span id="control-timer"></span>
                                        </p>
                                        <p id="input-help-mobile" class="input-help">
                                            使用常用手机号码作为用户名！</p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="smscode">
                                        短信验证码
                                    </label>
                                    <div class="controls">
                                        <input type="text" id="smscode" name="smscode" class="input-medium" maxlength="6"
                                            disabled="disabled" placeholder="请输入短信验证码" />
                                        <p id="input-help-smscode" class="input-help">
                                            短信验证码30分钟内有效！</p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="password-1">
                                        登录密码</label>
                                    <div class="controls">
                                        <input type="password" id="password-1" name="password" class="input-large" autocomplete="off"
                                            maxlength="12" onpaste="return false" onmousedown="this.oncontextmenu = function() { return false;} "
                                            onkeydown="if(event.ctrlKey) return false;" placeholder="请输入您的登录密码" data-rel="popover"
                                            data-trigger="focus" data-placement="left" data-original-title="温馨提醒" data-content="为了您的账户安全，请输入6-12位的密码。密码至少两个字母、两个数字、一个特殊字符！（字母区分大小写）" />
                                        <p id="input-help-password-1" class="input-help">
                                            6-12位，至少两个字母、两个数字、一个特殊字符！</p>
                                    </div>
                                </div>
                                <div class="control-group">
                                    <label class="control-label" for="repassword-1">
                                        确认密码</label>
                                    <div class="controls">
                                        <input type="password" id="repassword-1" name="repassword" class="input-large" autocomplete="off"
                                            maxlength="12" onpaste="return false;" onpaste="return false;" onmousedown="this.oncontextmenu = function() { return false;}"
                                            onkeydown="if(event.ctrlKey) return false;" placeholder="请再次输入您的登录密码" data-rel="popover"
                                            data-trigger="focus" data-placement="left" data-original-title="温馨提醒" data-content="为了您的账户安全，请输入6-12位的密码。密码至少两个字母、两个数字、一个特殊字符！（字母区分大小写）" />
                                        <p id="input-help-repassword-1" class="input-help">
                                            6-12位，至少两个字母、两个数字、一个特殊字符！</p>
                                    </div>
                                </div>
                                <div class="form-actions border-none background-none">
                                    <span class="ui-button ui-button-ok clearfix"><span class="ui-button-left">&nbsp;</span>
                                        <button type="submit" class="ui-button-text">
                                            同意协议并注册</button><span class="ui-button-right">&nbsp;</span></span> <span><a href="">
                                                xx用户协议</a> </span>
                                </div>
                                </form>
                            </div>
                        </div>
                        <div class="span3">
                            <div class="passport-register-quick">
                                <div class="passport-register-quick-header">
                                </div>
                                <div class="passport-register-quick-container">
                                    中国大陆手机用户，<br />
                                    编辑短信”<em>SK</em>“ 发送到：
                                    <br />
                                    <span class="mobile">1069099988</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="ui-box-simple-footer">
        </div>
    </div>
</div>
<div class="hide" id="myModal" style="width: 450px; height: 500px;">
    <div class="modal-header">
        <a data-dismiss="modal" class="close" href="javascript:$.fancybox.close();">×</a>
        <h3>
            对话框标题</h3>
    </div>
    <div class="modal-body">
        <h4>
            邮件发送成功!</h4>
        <p>
            我们已向您的邮箱<span id="reg-email"></span>发送认证邮件
        </p>
        <p>
            通过邮件中的链接地址，即可完成账号激活
        </p>
        <p>
            此链接将在<span>30</span>分钟后失效，失效后请重新填写信息
        </p>
        <p>
            <a target="_blank">登录邮箱</a>完成账号激活 <span><a href="javascript:void(0);" onclick="reReg()">
                换个邮箱注册</a></span>
        </p>
        <p class="mail-resend">
            还没收到邮件？<a id="resendemail" class="btn disabled" href="javascript:void(0);">重新发送</a>
            <span id="resendtimer">120</span>
        </p>
    </div>
</div>
@section css{
    @Url.Ayatta().StaticCss("jquery.fancybox")
}
@section js{
    @Url.Ayatta().StaticJs("jquery.validate.min")
    @Url.Ayatta().StaticJs("jquery.validate.extend")
    @Url.Ayatta().StaticJs("jquery.fancybox.pack")
    <script type="text/javascript">

        function emailSuffixSource(query, process) {
            var val = query;
            if (val.indexOf('@@') >= 0) {
                val = val.substring(0, val.indexOf('@@'));
            }
            var availableTags = [val + "@@qq.com", val + "@@163.com", val + "@@sina.com", val + "@@sohu.com", val + "@@yahoo.cn", val + "@@gmail.com", val + "@@hotmail.com"];
            return availableTags;
        }

        $(function () {
            $('[data-rel="popover"]').popover();
            $('#email').typeahead({
                source: emailSuffixSource,
                updater: function (item) {
                    setTimeout(function () {
                        document.getElementById('email').focus();
                        document.getElementById('email').blur();
                    }, 100);
                    return item;
                }
            });
            //$('#username').on('change', onChange);
            $('#form-register-by-email').validate({
                rules: { 'email': { required: true, email: true, remote: '/register/checkname' }, 'password': { required: true, password: true }, 'repassword': { required: true, password: false, equalTo: "#password" }, 'captcha': { required: true, rangelength: [4, 4], remote: '/register/checkcaptcha/1'} },
                messages: { 'email': { required: '请输入您的电子邮箱地址！', email: '请输入正确的电子邮箱地址！', remote: '该邮箱已被使用，请换一个！' }, password: { required: '请输入您的登录密码！', password: '6-12位，至少两个字母、两个数字、一个特殊字符！' }, repassword: { required: '请再次输入您的登录密码！', password: '6-12位，至少两个字母、两个数字、一个特殊字符！', equalTo: "两次输入的密码不一致！" }, 'captcha': { required: '请输入4位字符的验证码！（不区分大小写）', rangelength: '请输入4位字符的验证码！（不区分大小写）', remote: '验证码不正确，请重试！（4位字符，不区分大小写）'} },
                submitHandler: function (form) {
                    var param = $(form).serialize();
                    $.postJSON(form.action, param, function (result) {
                        if (result.Status == true) {
                            var html = $.format("<a href='javascript:void(0);' onclick='reSend(\"{0}\");'>重新发送</a>", result.Message);

                            $("#reg-email").html($("#username").val());
                            //$('#myModal').modal({ backdrop: false, keyboard: false, show: true });
                            //$.fancybox.open({ href: '#myModal', type: 'inline', modal: true, padding: 0 });

                        } else {
                            $("#register-message").html(result.Message);
                        }
                    });
                    return false;
                },
                errorPlacement: function (error, element) {
                    var id = "#input-help-" + $(element).attr('id');
                    var defaultHtml = $(id).html();
                    $(element).data("help", defaultHtml);
                    $(id).html(error);
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).removeClass(errorClass).addClass(validClass);
                    var defaultHtml = $(element).data("help");
                    var id = "#input-help-" + $(element).attr('id');
                    $(id).html(defaultHtml);
                }
            });
            $("#form-register-by-mobile").validate({
                rules: { 'smscode': { required: true, rangelength: [6, 6], remote: { url: "/register/checksmscode", type: "post", data: { mobile: function () { return $("#mobile").val(); }, smscode: function () { return $("#smscode").val(); } }} }, 'password': { required: true, password: true }, 'repassword': { required: true, password: true, equalTo: "#password-1"} },
                messages: { 'smscode': { required: '请输入您收到的短信验证码！', rangelength: '输入您收到的6位短信验证码！', remote: '短信验证码不正确或已过期！（30分钟内有效）' }, 'password': { required: '请输入您的登录密码！', password: '请输入符合格式的密码！' }, 'repassword': { required: '请再次输入您的登录密码！', password: '请输入符合格式的密码！', equalTo: "两次输入的密码不一致！"} },
                submitHandler: function (form) {
                    var param = $(form).serialize();
                    $.postJSON(form.action, param, function (result) {
                        if (result.Status == true) {
                            //$.fancybox.open({ href: '#myModal', type: 'inline', modal: true, padding: 0 });
                        } else {
                            alert(result.Message);
                            //$("#register-message").html(result.Message);
                        }
                    });
                    return false;
                },
                errorPlacement: function (error, element) {
                    var id = "#input-help-" + $(element).attr('id');
                    var defaultHtml = $(id).html();
                    $(element).data("help", defaultHtml);
                    $(id).html(error);
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).removeClass(errorClass).addClass(validClass);
                    var defaultHtml = $(element).data("help");
                    var id = "#input-help-" + $(element).attr('id');
                    $(id).html(defaultHtml);
                }
            });
        });

        function reReg() {
            $('#form-register-by-email').reset();
            $.fancybox.close();
        }

        function reSend(guid) {
            var url = "/register/resend";
            $.postJSON(url, { param: guid }, function (result) {
                if (result.Status == true) {
                    alert(0);
                } else {

                }
            });
        }

        function updateTimer() {
            var i = $("#resendtimer").html();
            if (i == 0) {
                $("#resendemail").removeClass('disabled').click(function () {
                    reSend();
                });
                return;
            }
            $("#resendtimer").html(i - 1);
            setTimeout(updateTimer, 1000);
        }

        function getSmsCode() {
            var mobile = document.getElementById('mobile').value;
            if (!mobile.isMobile()) {
                //alert('请输入正确的手机号码');
                $('#input-help-mobile').html("<span class='error'>请输入正确的手机号码！<span>");
            } else {
                $.postJSON('/home/smscode/0', { mobile: mobile }, function (result) {
                    if (result.Status == true) {
                        //$('#smscode').val('');
                        $("#control-getsmscode").hide();
                        document.getElementById('smscode').removeAttribute('disabled');
                        document.getElementById('mobile').setAttribute('readonly', 'readonly');
                        var info = "<span class='green'>我们已向该手机发送短信验证码，请注意查收！<span>";
                        $('#input-help-mobile').html(info);
                    } else {
                        var error = $.format("<span class='error'>{0}<span>", result.Message);
                        $('#input-help-mobile').html(error);

                    }
                });
            }
        }
    </script>
}
